package com.airsystem.pos.bengkel.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author Fanny Irawan Sutawanir (fannyirawans@gmail.com)
 */
public class PropertyReader {
	private static PropertyReader INSTANCE;

	private static final Properties PROPERTY_READER;

	private static final String KEY_DELETE_TRANSACTION_HISTORY;

	static {
		PROPERTY_READER = new Properties();

		ClassLoader loader = Thread.currentThread().getContextClassLoader();

		InputStream stream = loader.getResourceAsStream("application.properties");

		try {
			PROPERTY_READER.load(stream);
		} catch (IOException e) {
			e.printStackTrace();
		}

		KEY_DELETE_TRANSACTION_HISTORY = "DELETE_TRANSACTION_HISTORY";
	}

	private PropertyReader() {
		/* Delete all transaction data to Database testing purpose */
	}

	public static synchronized PropertyReader instance() {
		if (INSTANCE == null) {
			INSTANCE = new PropertyReader();
		}

		return INSTANCE;
	}

	public boolean isCanDeleteTransactionHistory() {
		int isCan = Integer.parseInt(PROPERTY_READER.get(KEY_DELETE_TRANSACTION_HISTORY).toString());

		return isCan == 1;
	}

	public String get(String key) {
		return PROPERTY_READER.get(key).toString();
	}
}